﻿Imports System.IO

Public Class StringTypeProvider
    Inherits TypeProvider
    Public Overrides ReadOnly Property Types As Type()
        Get
            Return {GetType(String)}
        End Get
    End Property
    Private Function ToBase64(S As String) As String
        Dim b(S.Length - 1) As Byte
        For i = 0 To S.Length - 1
            b(i) = Asc(S(i))
        Next
        Dim x = Convert.ToBase64String(b)
        Erase b
        Return x
    End Function
    Private Function FromBase64(S As String) As String
        Dim b = Convert.FromBase64String(s)
        Dim sx As String = ""
        For Each bx As Byte In b
            sx += Chr(bx)
        Next
        Erase b
        Return sx
    End Function
    Public Overrides Function ReadObject(T As Type) As Object
        Dim S = FromBase64(ReadBlock)
        Info.AddCache(S)
        Return S
    End Function
    Public Overrides Sub WriteObject(Obj As Object)
        Info.AddCache(Obj)
        Write(ToBase64(Obj))
    End Sub
End Class